Skip to content

Cleanup QuoteContext #8915

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 18, 2020
Merged

Conversation

nicolasstucki
Copy link
Contributor

No description provided.

@nicolasstucki nicolasstucki self-assigned this May 8, 2020
@nicolasstucki nicolasstucki requested a review from liufengyun May 8, 2020 14:45
@nicolasstucki nicolasstucki changed the title Move errors and warnings out of QuoteContext Cleanup QuoteContext May 8, 2020
@nicolasstucki nicolasstucki marked this pull request as ready for review May 8, 2020 16:25
}

val args = argsExpr match {
case Varargs(args) => args
case _ => qctx.throwError("Expected statically known argument list", argsExpr)
case _ => Reporting.throwError("Expected statically known argument list", argsExpr)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me the usability is better if methods can be called directly on qctx, as they don't need to remember another top-level name. What's the consideration to introduce Reporting?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can be imported if needed. The previous location was unintuitive and a few missed it. Additionally, this seems to be the only reason to not use anonymous QuoteContexts.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using the same trick as Dotty to introduce a method def qctx(using QuoteContext) = ...?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would also help. But, still errors and warnings do not belong there.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you, logically it is better to separate things.

The little worry I have is that Scala 3 macro authors may also be compiler hackers, compiler plugin writers, and some experience with Scala 2 macros. In all other cases, the error reporting is the same by calling ctx.error. So it would be nice to follow the convention.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As shown, that can be optionally supported with an implicit conversion.

It also seems that the users of the API did not find the reporting utilities or ended up finding the ones in the reflection API. The second is fine but the overhead could have been avoided by making it more explicit.

@nicolasstucki nicolasstucki force-pushed the cleanup-quote-context branch 3 times, most recently from 2514bd1 to 1576fff Compare May 11, 2020 12:30
@nicolasstucki nicolasstucki force-pushed the cleanup-quote-context branch from 1576fff to d262e99 Compare May 11, 2020 14:22
@@ -0,0 +1,35 @@
package scala.quoted

object Reporting {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or, can we make Reporting a trait, and make QuoteContext extend Reporting, the same as it is done in Dotty?

trait Reporting { thisCtx: Context =>
  // ...
}

For end-users, they don't need to know the concept Reporting, which improves usability.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would not help to decouple the concepts. The idea is not to use the QuoteContext directly at all and only let it implicitly track the current scope.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is not to use the QuoteContext directly at all and only let it implicitly track the current scope.

Thakns for explanation, I can see it is a good design principle. The little question still in my mind is why not use qctx directly if it can improve usability, like it's done in Dotty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that based on the users, the usability of this feature was not great. It may look simple to us because that is the way it is done internally in dotty. I prefer to make it clear for normal users than for users that know the compiler internals.

Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nicolasstucki nicolasstucki merged commit 76b42dd into scala:master May 18, 2020
@nicolasstucki nicolasstucki deleted the cleanup-quote-context branch May 18, 2020 08:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants